package com.appcenter.application.controller;

import com.appcenter.application.input.app.*;
import com.appcenter.application.service.AppService;
import com.appcenter.jz.config.ErrorJsonResult;
import com.appcenter.jz.config.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("api/services/jzappcenterservice/app")
@Api("应用相关服务操作API")
public class AppServiceController {
    @Autowired
    AppService appService;

    @ApiOperation(value = "查询应用列表", notes = "查询应用列表",produces = "application/json")
    @PostMapping("/getapps")
    public ResponseEntity<JsonResult> GetApps(@RequestBody GetAppsInput input) throws Exception {
        //throw new ErrorJsonResult("1000001", "捕获异常信息");
        JsonResult r = new JsonResult();
        try {
            r.setResult(appService.GetAllApps(input));
        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }
}
